<!--
 * @Author: wangding
 * @Date: 2020-11-09 17:44:26
 * @LastEditTime: 2020-11-10 11:58:41
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\device\sn\import.vue
-->
<template>
    <div>
        <el-dialog
        :title="$t('import')"
        :visible="newVisibleEdit"
        width="30%"
        @close="()=>{$store.commit('setNewVisibleEdit',false)}"
        :close-on-click-modal='false'
        >
            <el-row :gutter="20">
                <el-col :span="17" :offset="3">
                    <el-form ref="form" :model="form" label-width="120px" >
                        <el-form-item :label="$t('version.versionService.fileURL')" prop="file" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <baseFile v-model='form.file'></baseFile>
                        </el-form-item>
                        <el-form-item :label="$t('version.versionAdd.partNumber')" prop="partNo" :rules="[{ required: true, message: $t('index_js_notNull')}]">
                            <el-select v-model="form.partNo" :placeholder="$t('pleaseSelect')">
                                <el-option
                                v-for="item in textDataList.WIFI_PART_NUM"
                                :key="item.code"
                                :label="item.code"
                                :value="item.code">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button @click="()=>{$store.commit('setNewVisibleEdit',false)}">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import baseFile from '../../../components/common/baseFileInput'
export default {
    components: {
        baseFile
    },
    props: {

    },
    data() {
        return {
            form:{
                partNo:'',
                file:'',
            },
            textDataList:{}
        };
    },
    computed: {
        newVisibleEdit(){
            return this.$store.state.sysStore.newVisibleEdit
        }
    },
    watch: {

    },
    created() {

    },
    mounted() {
        this.getDictionaryBatch()
    },
    methods: {
        async getDictionaryBatch(){
            let res = await this.API.getDictionaryBatch({
                dictCodes:'WIFI_PART_NUM',
                lang:localStorage.getItem('lan') || 'zh_CN'
            })
            this.textDataList = res || {}
        },
        async snImportModuleInfo(){
            let res = await this.API.snImportModuleInfo(this.form)
            if(this.comm.showMsg(res.success)){
                this.$store.commit('setNewVisibleEdit',false)
                this.$emit('uploadData',true)
            }
        },
        save(formName){
            this.$refs[formName].validate((valid) => {
              if (valid) {
                  this.snImportModuleInfo()
              } else {
                console.log('error submit!!');
                return false;
              }
            });
        }

    },
};
</script>

<style  lang="less" scoped>

</style>
